version 14.2
set more off
set matsize 11000

***************************************************************************************************
* THIS ROUTINE GENERATES TABLE II OF WASEEM (2019) RESTAT
***************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d				cr
use				"$project_data\ExemptionCutoff_06_11.dta",clear
keep			if employee==1

/* BINNING DATA */

local 			var="wageinc"
local 			ubound=700000
local 			lbound=140000								
g 				double z0=`var'
sort			regnor year
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>`lbound' & z0<=`ubound'
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) 
g				logz0=log(z0)
mkspline 		z0s 10 = logz0

/* GENERATING TREATMENT DUMMIES */

g				tozero=0
replace			tozero=1 if `var'>150000 & `var'<180000 
replace			tozero=1 if `var'>180000 & `var'<200000 
replace			tozero=1 if `var'>200000 & `var'<300000 
replace			tozero=1 if `var'>300000 & `var'<350000 
g				tozero_year=0
replace			tozero_year=1 if `var'>150000 & `var'<180000 & year==2007
replace			tozero_year=1 if `var'>180000 & `var'<200000 & year==2008
replace			tozero_year=1 if `var'>200000 & `var'<300000 & year==2009
replace			tozero_year=1 if `var'>300000 & `var'<350000 & year==2010
g				nottozero=0
replace			nottozero=1 if `var'>300000 & `var'<450000
replace			nottozero=1 if `var'>500000 & `var'<550000
replace			nottozero=1 if `var'>600000 & `var'<650000
g				nottozero_year=0
replace			nottozero_year=1 if `var'>300000 & `var'<450000 & year==2007
replace			nottozero_year=1 if `var'>500000 & `var'<550000 & year==2007
replace			nottozero_year=1 if `var'>600000 & `var'<650000 & year==2007
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				bottom=(`var'<=300000)
g				trend_bottom=trend*bottom

/* COLUMN (1) */

local			i=1
local			j=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year logz0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)

/* COLUMN (2) */

local			i=1
local			j=`j'+1
qui				reg logchange i.year i.location_code tozero nottozero tozero_year nottozero_year logz0 if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0 & location_code>=0
matrix 			table[`i',`j']=r(mean)

/* COLUMN (3) */

local			i=1
local			j=`j'+1
qui				xi:reg logchange i.location_code*i.year tozero nottozero tozero_year nottozero_year logz0 if location_code>=0, cluster(regnor)
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0 & location_code>=0
matrix 			table[`i',`j']=r(mean)

/* COLUMN (4) */

local			i=1
local			j=`j'+1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year z0s*, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)

/* COLUMN (5) */

local			i=1
local			j=`j'+1
qui				reg logchange i.year i.location_code tozero nottozero tozero_year nottozero_year z0s* if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0 & location_code>=0
matrix 			table[`i',`j']=r(mean)

/* COLUMN (6) */

local			i=1
local			j=`j'+1
qui				xi:reg logchange i.location_code*i.year tozero nottozero tozero_year nottozero_year z0s* if location_code>=0, cluster(regnor)
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0 & location_code>=0
matrix 			table[`i',`j']=r(mean)

/* COLUMN (7) */

local			i=1
local			j=`j'+1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year logz0 z0s*, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0
matrix 			table[`i',`j']=r(mean)

/* COLUMN (8) */

local			i=1
local			j=`j'+1
qui				reg logchange i.year i.location_code tozero nottozero tozero_year nottozero_year logz0 z0s* if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0 & location_code>=0
matrix 			table[`i',`j']=r(mean)

/* COLUMN (9) */

local			i=1
local			j=`j'+1
qui				xi:reg logchange i.location_code*i.year tozero nottozero tozero_year nottozero_year logz0 z0s* if location_code>=0, cluster(regnor)
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]
local			i=`i'+6
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if tozero_year==0 & location_code>=0
matrix 			table[`i',`j']=r(mean)


/* PLACEBO */

use				"$project_data\ExemptionCutoff_06_11.dta",clear

/* BINNING DATA */

local 			var="wageinc"
local 			ubound=700000
local 			lbound=140000								//Earnings below this are subject to serious mean reversion
g 				double z0=`var'
sort			regnor year
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
keep 			if z0>`lbound' & z0<=`ubound'
qui				sum logchange,d
drop			if (logchange<r(p1) | logchange>r(p99)) 


/* GENERATING TREATMENT DUMMIES */

g				tozero=0
replace			tozero=1 if `var'>150000 & `var'<180000
replace			tozero=1 if `var'>180000 & `var'<200000 
replace			tozero=1 if `var'>200000 & `var'<300000 
replace			tozero=1 if `var'>300000 & `var'<350000 
g				tozero_year=0
replace			tozero_year=1 if `var'>150000 & `var'<180000 & year==2006
replace			tozero_year=1 if `var'>180000 & `var'<200000 & year==2007
replace			tozero_year=1 if `var'>200000 & `var'<300000 & year==2008
replace			tozero_year=1 if `var'>300000 & `var'<350000 & year==2009
g				nottozero=0
replace			nottozero=1 if `var'>300000 & `var'<450000
replace			nottozero=1 if `var'>500000 & `var'<550000
replace			nottozero=1 if `var'>600000 & `var'<650000
g				nottozero_year=0
replace			nottozero_year=1 if `var'>300000 & `var'<450000 & year==2006
replace			nottozero_year=1 if `var'>500000 & `var'<550000 & year==2006
replace			nottozero_year=1 if `var'>600000 & `var'<650000 & year==2006
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				bottom=(`var'<=300000)
g				trend_bottom=trend*bottom
g				logz0=log(z0)
mkspline 		z0s 10 = logz0

/* COLUMN (1) */

local			i=5
local			j=1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year logz0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]

/* COLUMN (2) */

local			i=5
local			j=`j'+1
qui				reg logchange i.year i.location_code tozero nottozero tozero_year nottozero_year logz0 if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]

/* COLUMN (3) */

local			i=5
local			j=`j'+1
qui				xi:reg logchange i.location_code*i.year tozero nottozero tozero_year nottozero_year logz0 if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]

/* COLUMN (4) */

local			i=5
local			j=`j'+1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year z0s*, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]

/* COLUMN (5) */

local			i=5
local			j=`j'+1
qui				reg logchange i.year i.location_code tozero nottozero tozero_year nottozero_year z0s* if location_code>=0, cluster(regnor)  
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]

/* COLUMN (6) */

local			i=5
local			j=`j'+1
qui				xi:reg logchange i.location_code*i.year tozero nottozero tozero_year nottozero_year z0s* if location_code>=0, cluster(regnor)
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]

/* COLUMN (7) */

local			i=5
local			j=`j'+1
qui				reg logchange i.year tozero nottozero tozero_year nottozero_year logz0 z0s*, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]

/* COLUMN (8) */

local			i=5
local			j=`j'+1
qui				reg logchange i.year i.location_code tozero nottozero tozero_year nottozero_year logz0 z0s* if location_code>=0, cluster(regnor)
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]

/* COLUMN (9) */

local			i=5
local			j=`j'+1
qui				xi:reg logchange i.location_code*i.year tozero nottozero tozero_year nottozero_year logz0 z0s* if location_code>=0, cluster(regnor) 
matrix			table[`i',`j']=_b[tozero_year]
matrix			table[`i'+1,`j']=_se[tozero_year]
local			i=`i'+2
matrix			table[`i',`j']=_b[nottozero_year]
matrix			table[`i'+1,`j']=_se[nottozero_year]

/* FORMATTING TABLE */ 

svmat 			table
keep			tab*
drop			table10-table12
keep			if _n<=10
forvalues		c=1/9 {
				g c`c'=string(table`c',"%9.3f")
}
forvalues		r=2(2)8 {
forvalues		c=1/9 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/9 {
replace			c`c'=string(table`c',"%9.0fc") in 9
}
g				ci="" 
replace			ci="$\mbox{\emph{to-zero}}$" in 1
replace			ci="$\mbox{\emph{not-to-zero}}$" in 3
replace			ci="$\mbox{\emph{to-zero}}$" in 5
replace			ci="$\mbox{\emph{not-to-zero}}$" in 7
replace			ci="Observations" in 9
forvalues		s=1/12 {
g				s`s'="&"
}
g				l="\\"
browse			ci s12 c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 s6 c7 s7 c8 s8 c9 l
